<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>建议新增</title>
	<link rel="icon" href="../../img/icon.png" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="../../../css/mui.css"/>
	<link rel="stylesheet" type="text/css" href="../../../css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="../../../css/app.css"/>
	<style type="text/css">
	</style>
</head>
<body>
	<!-- 头部TITLE -->
	<!-- <header class="mui-bar mui-bar-nav mui-bar-transparent"> -->
	<header class="mui-bar mui-bar-nav">
		<span class="mui-icon mui-icon-back" onclick="mui.back()"></span>
		<h1 class="mui-title">新增建议</h1>
	</header>
	<!-- 头部TITLE -->
	
	<!-- 主体部分 -->
	<div style="height: 80px;"></div>
	<div class="form">
		<!-- <input type="text" id="phone" placeholder="手机号码"/> -->
		<textarea class="textareaEdit" id="detail"></textarea>
		<input type="button" value="保存" 
			onclick="setOpinionAdd()"/>
	</div>
	<!-- 主体部分 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
<!-- 		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">广场</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToCamera()">
			<span class="mui-icon mui-icon-camera"></span>
			<span class="mui-tab-label">拍</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToChat()">
			<span class="mui-icon mui-icon-chatbubble"></span>
			<span class="mui-tab-label">消息</span>
		</a> -->
		<a class="mui-tab-item mui-active" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
	<!-- 底部菜单 -->
</body>
</html>


<script src="../../../js/mui.js"></script>
<script src="../../../js/app.js"></script>
<script type="text/javascript">
	// 登陆
	function setOpinionAdd(){
		var detail = mui("#detail")[0].value;
		if (!detail) {
			mui.toast('建议未填',{ 
				duration:'long', type:'div',
			});
			return
		}
		// 系统参数
		var sys = getSys();
		if (sys==null || sys.appAccess=='') { 
			setSys(); //参数更新
			setTimeout(function(){
				jumpToMyLogin();
			}, 1000);
		} 
		// 用户信息
		var userInfo = cacheGet(userInfoKey);
		var uid = userInfo ? userInfo.uid : 0;
		if (uid==0) {
			mui.toast('没有登陆',{ 
				duration:'short', type:'div',
			});
			setTimeout(function(){
				jumpToMyLogin();
			}, 500);
			return
		}
		mui.ajax(sys.domain+'/app/opinion/add',{
			data:{
				appAccess: sys.appAccess,
				uid:uid,
				detail:detail
			},
			dataType:'json', //服务器返回json格式数据
			type:'post', //HTTP请求类型
			timeout:10000, //超时时间设置为10秒
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			success:function(res){
				// mui.toast('res：'+res.code); return
				if (res.code==-1) {
					mui.toast('需要更新系统参数',{ 
						duration:'long', type:'div',
					});
					setTimeout(function(){
						setSys();
						jumpToMyLogin();
					},500);
				} else if (res.code!=0) {
					mui.toast(res.msg+'！',{ 
						duration:'long', type:'div',
					});
					return
				}
				var resId = res.data.opinionId;
				var resList = getOpinionCache();
				var list = resList.list;
				var idstr = resList.idstr;
				var listNew = new Array(), idstrNew = '';
				if (list.length > 0) {
					listNew = list; 
				}
				listNew[list.length] = {
					uid:uid,
					opinionId:resId,
					opinionDetail:detail
				};
				if (idstr=='') {
					idstrNew = idstr;
				} else {
					idstrNew = idstr+','+resId;
				}
				var resListNew = {
					list:listNew,
					idstr:idstrNew
				};
				// 更新缓存
				cacheSet(opinionList, resListNew);
				// 跳转到建议列表
				setTimeout(function(){
					jumpToMyOpinionList();
				}, 1000);
			},
			error:function(xhr,type,errorThrown){
				mui.toast('网络错误！',{ 
					duration:'short', type:'div',
				});
			}
		});
	}
	// 获取缓存
	function getOpinionCache(){
		var resList = cacheGet(opinionList);
		if (!resList) {
			var list = new Array(),  //数据数组
				idstring = ''; //ID字符串集合
			return {
				// 数据数组
				list: list,
				// 历史ID集合
				idstr: idstring
			};
		}
		return resList;
	}
</script>